#!/bin/bash
# scripts/one-click-deploy.sh

set -e

echo "开始一键部署开放广东数据开放平台..."

# 检查环境
echo "检查环境..."
if ! command -v docker &> /dev/null; then
    echo "错误: Docker 未安装"
    exit 1
fi

if ! command -v docker-compose &> /dev/null; then
    echo "错误: Docker Compose 未安装"
    exit 1
fi

# 启动私有仓库
echo "启动私有仓库..."
docker-compose -f docker-compose-registry.yml up -d

# 等待仓库启动
echo "等待仓库启动..."
sleep 10

# 构建和推送镜像
echo "构建和推送镜像..."
./scripts/build-and-push.sh

# 部署到生产环境
echo "部署到生产环境..."
docker-compose -f docker-compose.yml up -d

# 等待服务启动
echo "等待服务启动..."
sleep 60

# 健康检查
echo "执行健康检查..."
./scripts/health-check.sh

echo "一键部署完成！"
echo "访问地址: http://localhost"
echo "Registry UI: http://localhost:8080"
